<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 're.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
     <%
        String Driver="com.mysql.jdbc.Driver";
		String Url="jdbc:mysql://139.196.202.32:3306/secbox";
		try{
			Class.forName(Driver);
			System.out.println("success!!!");
			}
			catch(Exception e){
			e.printStackTrace();
			System.out.println("failure!!!");
			}
		try{	      
			Connection con=DriverManager.getConnection( Url,"root","secbox123*");
			 String email=(String)request.getParameter("email").trim();
	 		    String pw=(String)request.getParameter("password").trim();
		  		 PreparedStatement pstmt,pstmt1,pstmt2;	
		  		 String r2 = "select * from ftpusers where userid=?";
		  		 String r1= "insert into ftpusers(userid,passwd,uid,gid,homedir,shell,count,host,lastlogin, private_key) VALUES (?,?,1000,1000,?,'/sbin/nologin',0,'','','secboxkey')";
		  		 String r3 ="insert into quotalimits VALUES (?,'user','false','soft','10485760','0','0','0','0','0');";
		  		 
		  		 pstmt = con.prepareStatement(r1);	
		  		pstmt1 = con.prepareStatement(r2);
		  		pstmt2 =con.prepareStatement(r3);
		  		pstmt1.setString(1,email);
		  		pstmt2.setString(1,email);
		  		java.sql.ResultSet rs1 = pstmt1.executeQuery();
		  	if(rs1.next()){
		  		response.sendRedirect("reg_fail.jsp?zhuce=yes");
		  		 pstmt1.close() ;
		  		    con.close();	
		  	}
		  	else
		  		{
		  		pstmt.setString(1,email) ;
				pstmt.setString(2,pw) ;	
				String mulu ="/home"+"/"+email ;
				pstmt.setString(3,mulu) ;
				// pstmt.setString(4,privatekey) ;
				pstmt.executeUpdate();	
				pstmt2.executeUpdate();		
				    response.sendRedirect("reg_sucess.jsp?zhucecg=yes"); 
				    pstmt.close() ;
		  		    con.close();	
		  		 }
		  	        	     
           }catch(Exception e)
		  {
			e.printStackTrace();
		  };
	
     %>
  </body>
</html>
